package router

import (
	mp2 "duoke/controller/mp"
	"duoke/controller/mp/mpYoga"
	mpMiddleware "duoke/middleware"
	"duoke/utils/gstr"
	"duoke/utils/yaml"
	"github.com/gin-gonic/gin"
	"github.com/gogf/gf/v2/frame/g"
	"net/http/httputil"
	"net/url"
)

func LoadMp(r *gin.Engine) {
	config := yaml.GetConfig()
	// 反向代理
	r.Any("mp/v2/*any", func(c *gin.Context) {
		target := "http://127.0.0.1:" + config.Work.Port //转向的host
		remote, err := url.Parse(target)
		if err != nil {
			g.Dump("反向代理错误", err)
		}
		proxy := httputil.NewSingleHostReverseProxy(remote)
		c.Request.URL.Path = gstr.Replace(c.Request.URL.Path, "mp/v2", "api")
		proxy.ServeHTTP(c.Writer, c.Request)
	})
	/*
	 * 小程序
	 */
	r.POST("mp/notify/wxpay", mp2.Notify.Wxpay)                           // 拼团支付回调
	r.POST("mp/notify/merchant_coupon_pay", mp2.Notify.MerchantCouponPay) // 卡券支付回调
	r.POST("mp/notify/user_coupon_pay", mp2.Notify.UserCouponPay)         // 卡券支付回调
	r.POST("mp/notify/user_recharge_pay", mp2.Notify.UserRechargePay)     // 用户充值回调
	r.POST("mp/notify/course_notify", mp2.Notify.CourseNotify)            // 用户充值回调
	r.Any("mp/notify/separate_notify", mp2.Notify.SeparateNotify)         // 用户充值回调
	r.Any("mp/notify/short_notify", mp2.Notify.ShortNotify)
	r.Any("mp/notify/yoga_notify", mp2.Notify.YogaNotify)
	r.Any("mp/notify/yoga_course_notify", mp2.Notify.YogaCourseNotify)
	r.Any("mp/notify/withdrawal", mp2.Notify.Withdrawal)
	r.Any("mp/notify/poll", mp2.Notify.Poll)
	miniRouter1 := r.Group("mp")
	{
		miniRouter1.POST("user/login", mp2.User.Login)
		miniRouter1.POST("home/info", mp2.Home.Info)

		miniRouter1.POST("store/list", mp2.Store.List)
		miniRouter1.POST("goods/list", mp2.Goods.List)
		miniRouter1.POST("resource", mp2.Resource.Index)
		miniRouter1.GET("qrcode", mp2.Qrcode.Create)
		miniRouter1.POST("generate_code", mp2.Qrcode.GenerateCode)

		miniRouter1.POST("goods/info_simple", mp2.Goods.InfoSimple)

		// 课程目录
		miniRouter1.POST("course_list/list", mp2.CourseList.List)
		miniRouter1.POST("course_list/lecturer_menu", mp2.CourseList.LecturerMenu)
		miniRouter1.POST("course_list/search", mp2.CourseList.Search)
		miniRouter1.POST("course_lecturer/info", mp2.CourseLecturer.Info)
		miniRouter1.POST("course_menu/list", mp2.CourseMenu.List)
		miniRouter1.Any("notify/tencent_api", mp2.Notify.TencentApi)
		miniRouter1.POST("yoga/home_list", mpYoga.Home.List)
		miniRouter1.POST("yoga/teacher_list", mpYoga.Teacher.List)
		miniRouter1.POST("yoga/notice_list", mpYoga.Notice.List)
		miniRouter1.POST("yoga/notice_info", mpYoga.Notice.Info)

		miniRouter1.POST("yoga/group_class_list", mpYoga.GroupClass.List)
		miniRouter1.POST("yoga/teacher_class", mpYoga.GroupClass.TeacherList)
		miniRouter1.POST("yoga/private_classes", mpYoga.Teacher.PrivateClasses)
		miniRouter1.POST("yoga/hot_list", mpYoga.GroupClass.HotList)
		miniRouter1.POST("yoga/group_class_info", mpYoga.GroupClass.Info)
		miniRouter1.POST("yoga/venue_list", mpYoga.Venue.List)
		miniRouter1.POST("yoga/teacher_info", mpYoga.Teacher.Info)
		miniRouter1.POST("yoga/course_details", mpYoga.Teacher.CourseDetails)
		miniRouter1.POST("yoga/date_list", mpYoga.YogaDate.List)
	}
	// 登录授权
	miniRouter2 := r.Group("mp")
	{
		miniRouter2.Use(mpMiddleware.MpAuth())
		miniRouter2.POST("user/info", mp2.User.Info)
		miniRouter2.POST("user/update_phone", mp2.User.UpdatePhone)
		miniRouter2.POST("user/update_info", mp2.User.UpdateInfo)
		miniRouter2.POST("user/order", mp2.User.Order)
		miniRouter2.POST("user/recharge_pay", mp2.User.Recharge)
		miniRouter2.POST("user/cash", mp2.User.Cash)
		miniRouter2.POST("user/save", mp2.User.Save)
		miniRouter2.POST("user/ranking_version", mp2.User.RankingVersion)
		miniRouter2.POST("user/withdrawal", mp2.User.Withdrawal)

		// 分账
		miniRouter2.POST("separate_accounts/bind", mp2.Separate.Bind)
		miniRouter2.POST("separate_accounts/info", mp2.Separate.Info)
		miniRouter2.POST("separate_accounts/list", mp2.Separate.List)
		miniRouter2.POST("separate_accounts/create_order", mp2.Separate.CreateOrder)
		miniRouter2.POST("separate_accounts/pay_order", mp2.Separate.PayOrder)
		miniRouter2.POST("separate_apply/save", mp2.Separate.Apply)

		// 商户申请

		// 我的奖励
		miniRouter2.POST("reward/my", mp2.Reward.MyList)
		// 核销
		miniRouter2.POST("hexiao", mp2.Hexiao.Index)
		miniRouter2.POST("hexiao/list", mp2.Hexiao.List)
		// 上传
		miniRouter2.POST("upload/file", mp2.Upload.File)
		// 删除
		miniRouter2.POST("upload/file_del", mp2.Upload.FileDel)
		// 获取设置信息
		miniRouter2.POST("setting/info", mp2.Setting.Info)
		// 卡券
		miniRouter2.POST("coupon/merchant_pay_create", mp2.Coupon.MerchantPayCreate)
		miniRouter2.POST("coupon/user_pay_create", mp2.Coupon.UserPayCreate)
		miniRouter2.POST("coupon/behavior", mp2.Coupon.Behavior)

		// 复制视频和卡券
		miniRouter2.POST("coupon/copy", mp2.Coupon.Copy)
		miniRouter2.POST("coupon/list", mp2.Coupon.List)

		// 短视频
		miniRouter2.POST("shortvideo/gather_video", mp2.ShortVideo.GatherVideo)
		miniRouter2.POST("shortvideo/save", mp2.ShortVideo.Save)
		miniRouter2.POST("shortvideo/short_save", mp2.ShortVideo.ShortSave)
		miniRouter2.POST("shortvideo/create_order", mp2.ShortVideo.CreateOrder)
		miniRouter2.POST("shortvideo/pay_order", mp2.ShortVideo.PayOrder)

		miniRouter2.POST("short_watch/save", mp2.ShortWatch.Save)
		miniRouter2.POST("short_watch/save_watch_number", mp2.ShortWatch.SaveWatchNumber)
		miniRouter2.POST("course_share/save", mp2.CourseShare.Save)
		miniRouter2.POST("course_share/list", mp2.CourseShare.List)
		miniRouter2.POST("course_order/save", mp2.CourseOrder.Save)
		miniRouter2.POST("course_order/points_purchase", mp2.CourseOrder.PointsPurchase)
		miniRouter2.POST("course_order/carmine_payment", mp2.CourseOrder.CarminePayment)

		miniRouter2.POST("course_order/buy_info", mp2.CourseOrder.BuyInfo)

		miniRouter2.POST("course_order/pay_order", mp2.CourseOrder.PayOrder)
		miniRouter2.POST("course_video/give_points", mp2.CourseVideo.GivePoints) // 视频目录
		miniRouter2.POST("course_video/save_watch", mp2.CourseVideo.SaveWatch)
		// 语音朗读
		miniRouter2.POST("tool/get-voice", mp2.Tool.TextToVoice)

		// 腾讯im
		miniRouter2.POST("tencent_im/bind_user", mp2.TencentIm.BindUser)
		miniRouter2.POST("tencent_im/send_msg", mp2.TencentIm.SendMsg)
		miniRouter2.POST("tencent_im/admin_geotropism", mp2.TencentIm.AdminGeotropism)
		miniRouter2.POST("tencent_im/delete_msg", mp2.TencentIm.DeleteMsg)
		miniRouter2.POST("tencent_im/admin_msg_withdraw", mp2.TencentIm.AdminMsgWithdraw)

		miniRouter2.POST("tencent_store/result", mp2.TencentStore.Result)
		miniRouter2.POST("tencent_store/report", mp2.TencentStore.Report)
		miniRouter2.POST("shortvideo/short_info", mp2.ShortVideo.ShortInfo) // 短视频详情
		miniRouter2.POST("shortvideo/del", mp2.ShortVideo.Del)              // 短视频详情
		miniRouter2.POST("statistics/course_list", mp2.Statistics.Course)
		miniRouter2.POST("statistics/course_count", mp2.Statistics.CourseCount)
		miniRouter2.POST("statistics/course_info", mp2.Statistics.CourseInfo)
		miniRouter2.POST("statistics/short_video_info", mp2.Statistics.ShortVideoInfo)
		miniRouter2.POST("statistics/short_video_count", mp2.Statistics.ShortVideoCount)
		miniRouter2.POST("statistics/course_video", mp2.Statistics.CourseVideo)

		// 瑜伽
		miniRouter2.POST("yoga/user_info", mpYoga.User.Info)
		miniRouter2.POST("yoga/create_order", mpYoga.Order.CreateOrder)
		miniRouter2.POST("yoga/order_info", mpYoga.Order.OrderInfo)
		miniRouter2.POST("yoga/pay_order", mpYoga.Order.PayOrder)
		miniRouter2.POST("yoga/my_order", mpYoga.Order.MyOrder)
		miniRouter2.POST("yoga/reservation", mpYoga.Order.Reservation)
		miniRouter2.POST("yoga/course_create_order", mpYoga.CourseOrder.CreateOrder)
		miniRouter2.POST("yoga/course_pay_order", mpYoga.CourseOrder.PayOrder)
		miniRouter2.POST("yoga/order_list", mpYoga.Order.OrderList)
		miniRouter2.POST("yoga/my_course_order", mpYoga.CourseOrder.MyCourseOrder)
		miniRouter2.POST("yoga/order_detail", mpYoga.Order.OrderDetail)

		// 卡密
		miniRouter2.POST("carmine/list", mp2.Carmine.List)
		miniRouter2.POST("carmine/info", mp2.Carmine.Info)

		// 用户提现
		miniRouter2.POST("withdrawal/list", mp2.Withdrawal.List)
		miniRouter2.POST("withdrawal/pay_info", mp2.Withdrawal.Info)

		miniRouter2.POST("kuaidi/info", mp2.Kuaidi.Info)
	}
	// 登录授权+商品授权
	miniRouter3 := r.Group("mp")
	{
		miniRouter3.Use(mpMiddleware.MpAuth())
		miniRouter3.Use(mpMiddleware.Goods())
		miniRouter3.POST("goods/info", mp2.Goods.Info)
		miniRouter3.POST("goods/my_order", mp2.Goods.MyOrder)
		miniRouter3.POST("order/create", mp2.Order.Create)
		miniRouter3.POST("order/list", mp2.Order.List)
		miniRouter3.POST("group/list", mp2.Group.List)
		miniRouter3.POST("group/info", mp2.Group.Info)
		miniRouter3.POST("group/rise", mp2.Group.Rise)
		miniRouter3.POST("group/drop", mp2.Group.Drop)
		miniRouter3.POST("group/member", mp2.Group.Member)
		miniRouter3.POST("group/set_head", mp2.Group.SetHead)
		miniRouter3.POST("statistics/behavior", mp2.Statistics.Behavior)
		miniRouter3.POST("goods/behavior", mp2.Goods.Behavior)
		miniRouter3.POST("group/my", mp2.Group.My)
	}
	miniRouter4 := r.Group("mp")
	{
		miniRouter4.Use(mpMiddleware.NotAuth())
		miniRouter4.POST("course_video/info", mp2.CourseVideo.List) // 视频目录
		miniRouter4.POST("course_list/info", mp2.CourseList.Info)   // 栏目目录
		miniRouter4.POST("shortvideo/info", mp2.ShortVideo.Info)    // 短视频详情
		miniRouter4.POST("shortvideo/list", mp2.ShortVideo.List)    // 短视频详情
		miniRouter4.POST("home/index", mp2.Home.Index)
		miniRouter4.POST("yoga/course_info", mpYoga.Course.Info)
		miniRouter4.POST("yoga/course_list", mpYoga.Course.List)
	}
}
